"use strict";
// 数字枚举   ->原理：反向映射
var Role;
(function (Role) {
    Role[Role["Reporter"] = 1] = "Reporter";
    Role[Role["Developer"] = 2] = "Developer";
    Role[Role["Maintainer"] = 3] = "Maintainer";
    Role[Role["Owner"] = 4] = "Owner";
    Role[Role["Guest"] = 5] = "Guest";
})(Role || (Role = {}));
console.log(Role.Reporter);
console.log(Role);
// 字符串枚举
var Message;
(function (Message) {
    Message["Success"] = "\u606D\u559C\u60A8\uFF0C \u6210\u529F\u4E86";
    Message["Fail"] = "\u62B1\u6B49\uFF0C\u5931\u8D25\u4E86";
})(Message || (Message = {}));
//异构枚举   不建议使用
var Answer;
(function (Answer) {
    Answer[Answer["N"] = 0] = "N";
    Answer["Y"] = "yes";
})(Answer || (Answer = {}));
// 枚举成员  （常量，常量引用，计算枚举成员）
// Role.Reporter = 2
var Char;
(function (Char) {
    Char[Char["a"] = 0] = "a";
    Char[Char["b"] = 0] = "b";
    Char[Char["c"] = 4] = "c";
    Char[Char["d"] = Math.random()] = "d";
    Char[Char["e"] = '123'.length] = "e";
    Char[Char["f"] = 4] = "f";
})(Char || (Char = {}));
var month = [0 /* Jan */, 1 /* Feb */, 2 /* Mar */];
// 枚举类型
var E;
(function (E) {
    E[E["a"] = 0] = "a";
    E[E["b"] = 1] = "b";
})(E || (E = {}));
var F;
(function (F) {
    F[F["a"] = 0] = "a";
    F[F["b"] = 1] = "b";
})(F || (F = {}));
function render(result) {
    result.data.forEach(function (value) {
        console.log(value.id, value.name);
        if (value.age) {
            console.log(value.age);
        }
        value.id++;
    });
}
var result = {
    data: [
        { id: 1, name: 'a', sex: 'male' },
        { id: 2, name: 'b' }
    ]
};
render({
    data: [
        { id: 1, name: 'a', sex: 'male' },
        { id: 2, name: 'b' }
    ]
}); //类型断言
var chars = ['a', 'b'];
var fun = function (a, b) { return a + b; };
function getLib() {
    var lib = (function () { });
    lib.version = '1.0';
    lib.doSomething = function () { };
    return lib;
}
var lib1 = getLib();
lib1();
lib1.doSomething();
var lib2 = getLib();
//定义函数地方式
function resolve1(x, y) {
    return x + y;
}
var resolve2;
// resolve1(1, 2)
// 必选参数必须放在可选参数之前
function resolve5(x, y) {
    return y ? x + y : x;
}
resolve5(5);
// 函数定义默认值
function resolve6(x, y, z, q) {
    if (y === void 0) { y = 0; }
    if (q === void 0) { q = 1; }
    return x + y + z + q;
}
resolve6(1, undefined, 3); // 如果第二个参数不传  就会把3赋值给y
function resolve7(x) {
    var rest = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        rest[_i - 1] = arguments[_i];
    }
    return x + rest.reduce(function (pre, cur) { return pre + cur; });
}
console.log(resolve7(1, 2, 3, 4, 5), '------7');
function resolve8() {
    var rest = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        rest[_i] = arguments[_i];
    }
    var first = rest[0];
    if (typeof first === 'string') {
        return rest.join('');
    }
    if (typeof first === 'number') {
        return rest.reduce(function (pre, cur) { return cur + pre; });
    }
}
console.log(resolve8(1, 2, 3, 4, 5), '-----8');
console.log(resolve8('a', 'b', 'c'), '-----8');
